package lib.quasar.base.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;

import lib.quasar.util.DeviceUtil;
import lib.quasar.util.DimenUtil;
import lib.quasar.util.InputUtil;

/**
 * description: 对话框
 * created by kalu on 2018/3/29 14:24
 */
public abstract class BaseDialog extends Dialog {

    protected Activity activity;

    public BaseDialog(Activity activity) {
        super(activity);
        this.activity = activity;
    }

    public BaseDialog(Activity activity, int themeResId) {
        super(activity, themeResId);
        this.activity = activity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
        setContentView(initView());

        getWindow().setGravity(Gravity.CENTER);
        getWindow().setLayout(initWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);

        initData();
    }

    protected final int initWidth() {
        final int screWidth = (int) (DeviceUtil.getScreenWidth() * 0.95);
        final int realWidth = DimenUtil.dp2px(400);
        return Math.min(screWidth, realWidth);
    }

    protected abstract int initView();

    protected abstract void initData();
}